
App({
  globalData: {
    version: "1.6.7",
    app_id: "",
    num: 0,
    unionid: '',
    userInfo: null,
    openid: null,
    session_key: null,
    miniproid: '',
    shop_userID: "",
    uniq_openid: "",
    // http://check.libaizhaoshang.com   https://yzmp.henghi.com
    API_Base_URL: "https://t.gxmp.henghi.com",
    chatUrl: "https://chat.chuahi.cn/uri/chat/getChatUsers", //聊天
    HB_URL: "https://redbag.chuahi.cn",
    Gwang_URL: "https://t.guanwan.henghi.com",
    //API_Base_URL: "http://test.libaizhaoshang.com",
    //API_Base_URL: "http://yzmp.jacky.com",
    shareopenid: "0",
    currentStatu: "close",
    share_success: 0,
    getUserInfoFail: false,
    login: true,
    old_user_info: {},
    old_openid: "",
    typeArray: ["全部", "微商", "金融", "健康", "机构", "CEO", "科技", "讲师", "服务", "实体", "商贸", "咨询", "旅游", "其他"],
    time: 0,
    socket: "",
    offon: true,
    imID: "",
    isHide: false,
    socketConnectFail:false,
    Weburl:"wss://chat.chuahi.cn:7272",
    enable_topic:0,//是否展示wrq
    buy_goods:0//是否能购买商品
  },
  socketEven:null,
  onError: function(options) {
    var that = this;
    var networkType = "未知";
    wx.getNetworkType({
      success: res => {
        networkType = res.networkType
      }
    })
    wx.getSystemInfo({
      success: res => {
        wx.request({
          url: that.globalData.API_Base_URL + "/uri/Error/report",
          data: {
            app_id: that.globalData.app_id,
            version: that.globalData.version,
            openid: that.globalData.openid,
            error_uri: "",
            error_text: options,
            brand: res.brand,
            model: res.model,
            pixel_ratio: res.pixelRatio,
            screen_width: res.screenWidth,
            screen_height: res.screenHeight,
            widow_width: res.windowWidth,
            widow_height: res.windowHeight,
            language: res.language,
            wechat_version: res.version,
            system: res.system,
            platfrom: res.platform,
            fontsize: res.fontSizeSetting,
            sdkversion: res.SDKVersion,
            network: networkType,
            user_agent: ""
          },
          success: res = {

          }
        })
      },
    })
  },
  onHide: function () {
    // this.globalData.isHide=true
    // this.globalData.socket.close()
  },
  socketInit: function () {
    var that = this
    this.globalData.socket = wx.connectSocket({
      url: this.globalData.Weburl,
      fail(err) {
        console.log(err)
        if (err) {
          console.log('Socket连接失败')
        }
      },
      success() {
        wx.onSocketOpen((res) => {
          console.log('WebSocket打开成功');
          if(wx.getStorageSync('userInfo').nickname){
            wx.sendSocketMessage({
              data: JSON.stringify({
                appid: that.globalData.imID,
                type: 'login',
                uid: wx.getStorageSync('userInfo').openid,
                uid_name: wx.getStorageSync('userInfo').nickname,
                uid_head: wx.getStorageSync('userInfo').src
              })
            })
          }
        })
        wx.onSocketMessage(res => {
          var ress = JSON.parse(res.data)
          console.log(ress)
          if (that.socketEven!=null){
            that.socketEven(ress)
          }
        })
        wx.onSocketClose(res=>{
          if (res.code != 1000){
            console.log("断开连接，准备重连...")
            if (this.globalData.socket != '') {
              wx.closeSocket()
              this.socketInit()
            } else {
              this.socketInit()
            }
          }
        })
      }
    })
  },
  onShow: function() {
    var that = this;
    if (this.globalData.socket != ''){
      wx.closeSocket()
      this.socketInit()
    }else{
      this.socketInit()
    }
    if (wx.getExtConfig) {
      wx.getExtConfig({
        success(res) {
          console.log(res.extConfig)
          console.log('---------------------------------')
          that.globalData.miniproid = res.extConfig.miniproid //"100005" //
          that.globalData.app_id = res.extConfig.appid //"wxdcc047290f507f75"// 
          that.globalData.shop_userID = res.extConfig.shop_userID
          that.globalData.imID ="10000" //res.extConfig.imID
          // that.socketInit()
          wx.getStorage({
            key: 'num',
            success: function(res) {
              that.globalData.num = res.data
            },
          })
          if (new Date().getTime() - that.getDate_() > 86400000) {
            // 现在的时间比当天24点的时间大一天的话，说明这一天已经过去了，可以初始化收藏
            wx.setStorage({
              key: 'num',
              data: 0,
            })
            that.globalData.num = 0
          }
          wx.request({
            url: that.globalData.API_Base_URL + "/uri/Configoption/getOption",
            data: {
              version: that.globalData.version,
              name: "about_us,deep_cooperation,share_title",
              miniproid: that.globalData.miniproid
            },
            success: res => {
              that.globalData.share_title = res.data.data.share_title;
              that.globalData.deep_cooperation = res.data.data.deep_cooperation;
              that.globalData.about_us = res.data.data.about_us;
            }
          })
          var tomorrow = wx.getStorageSync("TIME");
          if (tomorrow < new Date().getTime() / 1000 || tomorrow == undefined) {
            wx.setStorageSync('TIME', new Date(new Date().setHours(24, 0, 0, 0)) / 1000)
            wx.setStorageSync("FIND_SUM", 1);
          }
          wx.request({
            url: that.globalData.API_Base_URL + "/uri/Auditing/isAuditing",
            data: {
              version: that.globalData.version,
              miniproid: that.globalData.miniproid
            },
            success: res => {
              if (res.data.code == 0) {
                if (res.data.sign == 0) {
                  that.globalData.isSign = 0;
                } else {
                  that.globalData.isSign = 1;
                }
              }
            }
          })
          wx.getNetworkType({
            success: res => {
              var networkType = res.networkType
              if (networkType == "none" || networkType == "unknown") {
                wx.hideLoading();
                wx.showModal({
                  title: '提示',
                  content: '请检查网络',
                  showCancel: false,
                  success: res => {

                  }
                })
              }
            }
          })
        }
      })
    }

  },
  
  getDate_: function() {
    var todayYear = (new Date()).getFullYear();
    var todayMonth = (new Date()).getMonth();
    var todayDay = (new Date()).getDate();
    var todayTime = (new Date(todayYear, todayMonth, todayDay)).getTime(); //毫秒
    return todayTime
  }
})
// 	{
// 	"pagePath": "pages/aQuan/aQuan",
// 	"text": "圈子",
// 	"iconPath": "image/tabBar/tabBar3.png",
// 	"selectedIconPath": "image/tabBar/tabBar3-1.png"
// },